#%%
import cv2 as cv 
import numpy as np 

img = np.random.randint(0,256,size=[2,4,3],dtype = np.uint8)

# 将BGR色彩空间转化为灰度色彩空间
# 转化规则 `GRAY =0.299×R +0.587*G +0.114*B` 
rst = cv.cvtColor(img,cv.COLOR_BGR2GRAY)

print("img=\n",img)

print("rst=\n",img)

print("像素点（1,0）直接计算得到的值=",img[1,0,0]*0.114 + img[1,0,1]*0.587 + img[1,0,2]*0.299)

print("像素点（1,0）使用公式cv2.cvtLolor()转换值=",rst[1,0])


#%%
import cv2 as cv
import numpy as np 

# ========================= 测试一下 opencv 中蓝色的 HSV模式值

imgBlue = np.zeros([1,1,3],dtype = np.uint8)

imgBlue[0,0,0] = 255

Blue = imgBlue

BlueHSV = cv.cvtColor(Blue,cv.COLOR_BGR2HSV)
print("Blue=\n",Blue)


print("BlueHSV=\n",BlueHSV)


#%%
import cv2 as cv 


img = cv.imread("/home/heron/Desktop/linux_notes/python/img/shuiyin.png")

hsv = cv.cvtColor(img,cv.COLOR_BGR2HSV)

h,s,v = cv.split(hsv)

# 将v通道变成255
v[:,:]=255

newHSV =cv.merge([h,s,v])

art = cv.cvtColor(newHSV,cv.COLOR_HSV2BGR)

cv.imshow("img",img)

cv.imshow("art",art)

cv.waitKey()

cv.destroyAllWindows()

#%%
import cv2 as cv

cv.namedWindow("img",cv.WINDOW_AUTOSIZE)

img = cv.imread("/home/heron/Desktop/linux_notes/python/img/pic001.png")

print(img.shape)
cv.imshow("img",img)

bgra = cv.cvtColor(img,cv.COLOR_BGR2BGRA)

print("bgra.shape = ",bgra.shape)

b,g,r,a = cv.split(bgra)

a[:,:]=100
bgra = cv.merge([b,g,r,a])

cv.imshow("img2",bgra)
cv.imwrite("/home/heron/Desktop/linux_notes/python/img/alpha.png",bgra)

cv.waitKey()
cv.destroyAllWindows()
